#include "cmsis_os.h" 
#include "stm32f4xx.h" 
#include "GPIO_STM32F4xx.h"             // Keil::Device:GPIO
#include "rl_fs.h"                      /* FileSystem definitions             */
#include <stdio.h>                      /* Standard I/O .h-file               */
#include <ctype.h>                      /* Character functions                */
#include <string.h>                     /* String and memory functions        */
#include "Driver_MCI.h"                 // ::Drivers:MCI
//Include files for DSP library
#include "fsfunctions.h" 
#include "arm_math.h"
#include "keybord/Keybord.h"

#define BLOCK_SIZE            32
#define NUM_TAPS              32
#define TEST_LENGTH_SAMPLES   4096
uint32_t numBlocks = TEST_LENGTH_SAMPLES/BLOCK_SIZE;

static  q15_t firState[BLOCK_SIZE + NUM_TAPS - 1];
static q15_t testOutput[TEST_LENGTH_SAMPLES];
arm_fir_instance_q15 FIRinstance;	
q15_t *inputStream, *outputStream; 	

const q15_t firCoeffs[NUM_TAPS] = {
   -124,   -113,   -108,   -108,   -136,    -202,   -335,   -531,
   -763,   -894,   -643,    529,   3454,    9294,  19341,  25561,
  19341,   9294,   3454,    529,   -643,    -894,   -763,   -531,
   -335,   -202,   -136,   -108,   -108,    -113,   -124,   -129
};

uint32_t FIRblockSize = BLOCK_SIZE;


static void init_pins (void) {
	GPIO_PortClock(GPIOA, ENABLE);
	GPIO_PortClock(GPIOB, ENABLE);
	GPIO_PinConfigure(GPIOA,12,GPIO_MODE_OUTPUT,GPIO_OUTPUT_PUSH_PULL, GPIO_OUTPUT_SPEED_100MHz,GPIO_NO_PULL_UP_DOWN);
	GPIO_PinConfigure(GPIOB,14,GPIO_MODE_OUTPUT,GPIO_OUTPUT_PUSH_PULL, GPIO_OUTPUT_SPEED_100MHz,GPIO_NO_PULL_UP_DOWN);
	GPIO_PinConfigure(GPIOB,15,GPIO_MODE_OUTPUT,GPIO_OUTPUT_PUSH_PULL, GPIO_OUTPUT_SPEED_100MHz,GPIO_NO_PULL_UP_DOWN);	
	GPIO_PinWrite(GPIOB,14,1);
	GPIO_PinWrite(GPIOB,15,1);
}

static void pingLED(uint32_t delay, uint32_t times) {
	uint32_t t;
	for (t = 0; t < times; t++)
	{
		GPIO_PinWrite(GPIOA,12,1);		
    osDelay(delay);  
    GPIO_PinWrite(GPIOA,12,0);	
		osDelay(delay); 
	}
}

static void OnLED()  { GPIO_PinWrite(GPIOA,12,1);	}
static void OffLED() { GPIO_PinWrite(GPIOA,12,0);	}

int main (void) {  
	enum KeyStroke key;
	SystemInit();
	init_pins();
	pingLED(1000, 5);
	initKeyboard();
	for (;;) 
	{
		key=waitKeyStroke();
		if (key==F1)	pingLED(1000, 5);			
	}	
}
